<%@ page language="java" import="java.util.*,other.*,java.text.*" pageEncoding="UTF-8"%>
<%
    List filelist=(List)session.getAttribute("filelist");
    String dealercode=(String)session.getAttribute("dealercode");
    String dealername=(String)session.getAttribute("dealername");    
    String filetype=(String)session.getAttribute("filetype");
    String beginDate=(String)session.getAttribute("beginDate");
    String endDate=(String)session.getAttribute("endDate"); 
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");             			        
    GetYToday T=new GetYToday();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>文件预检分发管理</title>
<link rel="stylesheet" type="text/css" media="all" href="skins/aqua/theme.css"  />
<script type="text/javascript" src="JS/calendar.js"></script>
<script type="text/javascript" src="JS/calendar-en.js"></script>
<script type="text/javascript" src="JS/calendar-setup.js"></script>
<style>
body{
}
div,body{
margin:0px auto;}
#box{
	width:1152px;
	background:url(images/bg_00.png) repeat-y;
}
.level_1{
width:1120px;
height:35px;
border:1px #67C8F5 solid;
background:#E2EAF5;}
.level_2{
	width:1120px;
	margin-top:20px;
}
.level_1_1{
	float:left;
	width:136px;
	height:35px;
	background:#E2EAF5;
}
.level_1_2{
	float:left;
	width:140px;
	height:35px;
	background:#E2EAF5;
}
.level_1_3{
	float:left;
	width:90px;
	height:35px;
	background:#E2EAF5;
	font-size:12px;
	line-height:35px;
}
.level_1_4{
	float:left;
	width:77px;
	height:35px;
	background:#E2EAF5;
}
.level_1_5{
float:left;
width:65px;
height:35px;
background:#E2EAF5;
}.level_1_6{
	float:left;
	width:103px;
	height:35px;
	background:#E2EAF5;
}
.level_1_1_a{
	float:left;
	width:75px;
	height:35px;
	background:#E2EAF5;
	line-height:35px;
	font-size:12px;
}
.level_1_1_b{
	float:left;
	width:60px;
	height:35px;
	background:#E2EAF5;
}
.level_1_2_a{
float:left;
width:80px;
height:35px;
background:#E2EAF5;
line-height:35px;
font-size:12px;
}
.level_1_2_b{
	float:left;
	width:60px;
	height:35px;
	background:#E2EAF5;
}
.kw{
border-top:1px solid #D7ECED;
border-left:1px solid #D7ECED;}
.kw td{
border-bottom:1px solid #D7ECED;
border-right:1px solid #D7ECED;
color:#2D74C4;
font-size:12px;}
.title_1{
font-weight:bold;
font-size:12px;
color:#2D74C4;
line-height:30px;
}
.center_td{
text-align:center;}
.bold{
font-weight:bold;
}
#footer{
	height:30px;
	width:1152px;
	background:url(images/bottom.png) bottom;
}
#top{
width:1152px;
height:110px;
background:url(images/top9.png)
}
.left_td{
text-align:left;
padding-left:10px;}
.td_1{
padding-left:10px;}
</style>
<script language="javascript">
function selectit(){   
 var form=document.formselect; 
 var action=event.srcElement.name; 
 for (var i=0;i<form.elements.length;i++){//遍历表单项 
      var e = form.elements[i] 
      if (e.name == "IsRepeatDealer") 
         e.checked =(action=="selectall")?(form.selectall.checked):(!e.checked)  
      }
  }
 function showvalue(){
	 var value="";
	 var checks=document.getElementsByName("IsRepeatDealer");
	 for(var i=checks.length-1;i>=0;i--){
	     if(checks[i].checked){
	        value=value+checks[i].value+"@@";         
	     }
	 }
	 document.getElementById("Issuedfile").value = value;
 }
//ajax 
var xmlHttp=null;
function GetXmlHttpObject(){   
   try{
      xmlHttp=new XMLHttpRequest();
   }catch(e){
      try{
         xmlHttp=new ActiveXObject("Msxm12.XMLHTTP");
      }catch(e){
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
   return xmlHttp;
}

function FileIssue(){
  var value="";
  var checks=document.getElementsByName("IsRepeatDealer");
  for(var i=checks.length-1;i>=0;i--){
      if(checks[i].checked){
         value=value+checks[i].value+"@@";         
      }
  }
  
  var url="FileIssue.jsp";
  url=url+"?Issuedfile="+value;
  url=url+"&sid="+Math.random();
  alert(url);
  xmlHttp.onreadystatechange=QueryFileReturnState;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);  
}

function FileAbandon(){
  xmlHttp=GetXmlHttpObject();
  if(xmlHttp==null){
     alert("You Browser don't support the ajax!");
     return;
  }
  var url="FileAbandon.jsp";
  url=url+"?sid="+Math.random();
  xmlHttp.onreadystatechange=ReturnState;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function ReturnState(){
  if(xmlHttp.readyState==4){
    if(xmlHttp.status==200){
       window.alert("所选文件放弃成功!");
    }else{
       window.alert("所请求的页面不正常!");
    }
  }
}

function QueryFileReturnState(){
  if(xmlHttp.readyState==4){
    if(xmlHttp.status==200){
       window.alert("所选文件下发成功!");
    }else{
       window.alert("所请求的页面不正常!");
    }
  }
}
 
function showrvalue(){
    var value="";                                         	
	var checks=document.getElementsByName("IsRepeatDealer");
	for(var i=checks.length-1;i>=0;i--){	  
		if(checks[i].checked){
           value=value+checks[i].value + "@@";        		
		}
	}
	document.getElementById("Renouncefile").value = value;
}

function QueryFile(){
  xmlHttp=GetXmlHttpObject();
  if(xmlHttp==null){
     alert("You Browser don't support the ajax!");
     return;
  }  
  var url="QueryFile.jsp";
  url=url+"?dealercode="+document.getElementById("dealercode").value;
  url=url+"&dealername="+document.getElementById("dealername").value;
  url=url+"&SelectName="+document.getElementById("SelectName").value;
  url=url+"&begintime="+document.getElementById("input_a").value;
  url=url+"&endtime="+document.getElementById("input_b").value;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=ReturnQueryState;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function ReturnQueryState(){
  if(xmlHttp.readyState==4){
     if(xmlHttp.status==200){     
        window.alert("查询成功!");   
     }else{
        window.alert("请求的页面不正常!");
     }
  }
}

function initshow(){
  var flag = '<%=(String)session.getAttribute("alertvalue")%>';
  if(flag==''){
  }else if(flag!=''){
     alert(flag);
  }  
}


    function sortTable(sTableId,iCol,sDataType){
    var oTable=document.getElementById(sTableId);//获取表格的ID
    var oTbody=oTable.tBodies[0]; //获取表格的tbody
    var colDataRows=oTbody.rows; //获取tbody里的所有行的引用
    var aTRs=new Array; //定义aTRs数组用于存放tbody里的行
    for(var i=0;i<colDataRows.length;i++){//依次把所有行放如aTRs数组/
    aTRs.push(colDataRows[i]);
    }
    /***********************************************************************
    sortCol属性是额外给table添加的属性，用于作顺反两种顺序排序时的判断，区分
    首次排序和后面的有序反转
    ************************************************************************/
    if(oTable.sortCol==iCol){//非首次排序
    aTRs.reverse();
    }
    else{ //首次排序
    aTRs.sort(generateCompareTRs(iCol,sDataType));
    }
    var oFragment=document.createDocumentFragment();//创建文档碎片/
    for(var i=0;i<aTRs.length;i++){ //把排序过的aTRs数组成员依次添加到文档碎片
    oFragment.appendChild(aTRs[i]);
    }
    oTbody.appendChild(oFragment); //把文档碎片添加到tbody,完成排序后的显示更新
    oTable.sortCol=iCol;//把当前列号赋值给sortCol,以此来区分首次排序和非首次排序，//sortCol的默认值为-1
    };
    //比较函数，用于两项之间的排序
    function generateCompareTRs(iCol,sDataType){
    return function compareTRs(oTR1,oTR2){
    var vValue1=convert(oTR1.cells[iCol].firstChild.nodeValue,sDataType);
    var vValue2=convert(oTR2.cells[iCol].firstChild.nodeValue,sDataType);
    if(vValue1<vValue2){
    return -1;
    }
    else if(vValue1>vValue2){
    return 1;
    }
    else{
    return 0;
    }
    };
    };
    //数据类型转换函数
    function convert(sValue,sDataType){
    switch(sDataType){
    case "int":return parseInt(sValue);
    case "float": return parseFloat(sValue);
    case "date":return sValue.toString();;
    default:return sValue.toString();
    }
    };

</script>
</head>
<body onload="initshow()">
<div id="top"></div>

<div id="box">

<div class="level_1">
<form action="QueryFile.jsp" name="form1" method="post">
<div class="level_1_2_a" align="right" style="width:66px;">经销商代码:</div>
<%if(dealercode!=null || dealercode==""){ %>
<div class="level_1_2_a" align="right" style="width:77px;">
<input type="text" value="<%=dealercode%>" name="dealercode" id="dealercode" style="margin-top: 7px; width: 67px; font-family:Arial; font-size:10px; line-height:14px;"></input>
</div>
<%} else { %>
<div class="level_1_2_a" align="right" style="width:77px;">
<input type="text" value="" name="dealercode" id="dealercode" style="margin-top: 7px; width: 67px; font-family:Arial; font-size:10px; line-height:14px;"></input>
</div>
<%} %>
<div class="level_1_2_a" align="right" style="width:70px;">经销商名称:</div>
<%if(dealername!=null || dealername==""){%>
<div class="level_1_2_a" align="right" style="width:87px;">
<input type="text" value="<%=dealername%>" name="dealername" id="dealername" style="margin-top: 7px; width: 77px; font-family:Arial; font-size:10px; line-height:14px;"></input>
</div>
<%} else { %>
<div class="level_1_2_a" align="right" style="width:87px;">
<input type="text" value="" name="dealername" id="dealername" style="margin-top: 7px; width: 77px; font-family:Arial; font-size:10px; line-height:14px;"></input>
</div>
<%}%>

<div class="level_1_2_a" align="right" style="width:56px;">处理动作:</div>
<div class="level_1_2_a" align="right" style="width:130px;">
   <select name="SelectName" id="SelectName" style="margin-top: 8px; width: 130px; font-family:Arial; font-size:10px; line-height:14px;" >
    <%if (filetype.equals("2")) {%>   
        <option value ="2" selected="selected">重复到达需下发</option>
        <option value ="3">重复到达无需下发</option>             
  <% } else if(filetype.equals("3")) {%>
        <option value ="2">重复到达需下发</option>
        <option value ="3" selected="selected">重复到达无需下发</option>        
  <% } %>
  </select>
</div>

<div class="level_1_3" align="right" style="width:56px;">传输时间:</div>
<div class="level_1_4">
  <input name="begintime" type="text" value="<%=beginDate%>" id="input_a" size="9" style="margin-top: 7px; width: 70px; height:14px; font-family:Arial; font-size:10px; line-height:14px;" /> 
  <script type="text/javascript">
         Calendar.setup({
         inputField     :    "input_a",      // id of the input field
         ifFormat       :    "%Y-%m-%d",       // format of the input field
         showsTime      :    true,            // will display a time selector
		 timeFormat     :    "24",
		
         button         :    "f_date_a",   // trigger for the calendar (button ID)
         singleClick    :    true,           // double-click mode
         step           :    1                // show all years in drop-down boxes (instead of every other year as default)
         });
  </script>   
</div>
<div class="level_1_4">
<input name="endtime" type="text" value="<%=endDate%>" id="input_b" size="9" style="margin-top: 7px; width: 70px; height:14px; font-family:Arial; font-size:10px; line-height:14px;" />     
  <script type="text/javascript">
        Calendar.setup({
        inputField     :    "input_b",      // id of the input field
        ifFormat       :    "%Y-%m-%d",       // format of the input field
        showsTime      :    true,            // will display a time selector
		timeFormat     :    "24",
		
        button         :    "f_date_b",   // trigger for the calendar (button ID)
        singleClick    :    true,           // double-click mode
        step           :    1                // show all years in drop-down boxes (instead of every other year as default)
        });
  </script>           
</div>
<div class="level_1_2_a" align="right" style="width:5px;"></div>
<div class="level_1_6" style="width:85px;">
<input type="image" src="images/bnt.jpg" style="margin-top:7px; border:none"/>
</div>
</form>

  <form action="FileIssue.jsp" method=post name=formx1>
  <div class="level_1_6" style="width:90px;">
  <input type="hidden" name="Issuedfile" id="Issuedfile"/>
  <input type="image" src="images/bnt14.jpg" onclick="showvalue()" style="margin-top:7px; border:none"/>
  </div>
  </form> 
  
  <form action="FileAbandon.jsp" method=post name=formx2>
  <div class="level_1_6" style="width:60px;">
  <input type="hidden" name="Renouncefile" id="Renouncefile"/>
  <input type="image" src="images/bnt17.jpg" onclick="showrvalue()" style="margin-top:7px; border:none"/>
  </div>
  </form>
  
  
   
</div>

<div class="level_2">
  <form action="FileAbandon.jsp" method="post" name="formselect">
  <table class="kw" width="1125" border="0" cellspacing="0" id="tbmain">     
     <thead>
      <tr>             
        <td class="title_1" width="60" align="center" height="40"><input type="checkbox" name="selectall" onclick="selectit()"/>全选</td>
        <td class="title_1" width="80" align="center" height="40" onclick="sortTable('tbmain',1)" style="cursor:pointer">经销商代码</td>
        <td class="title_1" width="190" align="center" height="40" onclick="sortTable('tbmain',2)" style="cursor:pointer">经销商名称</td>
        <td class="title_1" width="415" align="center" height="40" onclick="sortTable('tbmain',6,'date')" style="cursor:pointer">文件名称</td>
        <td class="title_1" width="60" align="center" height="40" onclick="sortTable('tbmain',3)" style="cursor:pointer">文件类型</td>
        <td width="80" class="title_1" align="center" height="40" onclick="sortTable('tbmain',4,'date')" style="cursor:pointer">文件到达时间</td>        
        <td width="80" class="title_1" height="40" align="center">是否重复到达</td>
		<td class="title_1" width="80" height="40" align="center">有效行数</td>
        <td width="80" class="title_1" height="40" align="center">有效数量</td> 
      </tr>
      </thead>
      <tbody>
      <% if ((filelist!=null) || (filelist.size()==0)){             
             SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd"); 
             SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");    
             for(int k=0;k<filelist.size();k++){
                 String s=filelist.get(k).toString();
                 s=s.replace("]","");
                 s=s.replace("[","");
                 String[] m=s.trim().split(","); 
                 String returnvalue=(String)m[8].trim()+"!!"+(String)m[10].trim()+"!!"+(String)m[9].trim()+"!!"+(String)m[0].trim()+"!!"+(String)m[3].trim()+"!!"+(String)m[2].trim();                 
                 String colorvalue=(String)m[9].trim();                                   	     	           
      %>  
      <% if(colorvalue.equals("4")){%>
      <tr>
        <td align="center" width="60"><input name="IsRepeatDealer" id="IsRepeatDealer" type="checkbox" value="<%=returnvalue%>"/></td>
        <% if (m[0]!=null) { %>
           <td class="center_td bold" align="center" width="80" bgcolor="#kdfafe"><%=(String)m[0].trim()%></td>
        <%} else {%>  
           <td  class="center_td bold" align="center" width="80" bgcolor="#kdfafe"></td>
        <%}%>
        <% if (m[1]!=null) { %>
           <td class="center_td bold" align="center" width="190" bgcolor="#kdfafe"><%=(String)m[1].trim()%></td>
        <%} else {%>  
           <td class="center_td bold" align="center" width="190" bgcolor="#kdfafe"></td>
        <%}%>
        
        <% if (m[2]!=null) { %>
           <td class="center_td bold" align="center" width="415" bgcolor="#kdfafe"><%=(String)m[2].trim()%></td>
        <%} else {%>  
           <td class="center_td bold" align="center" width="415" bgcolor="#kdfafe"></td>
        <%}%>        
        
        <% if (m[3]!=null) { %>
           <td class="center_td bold" align="center" width="60" bgcolor="#kdfafe"><%=(String)m[3].trim()%></td>
        <%} else {%>  
           <td class="center_td bold" align="center" width="60" bgcolor="#kdfafe"></td>
        <%}%>
        <% if (m[4]!=null) { %>
           <td class="center_td bold" align="center" width="80" bgcolor="#kdfafe"><%=sf.format(sf.parse((String)m[4].trim()))%></td>
        <%} else {%>  
           <td class="center_td bold" align="center" width="80" bgcolor="#kdfafe"></td>
        <%}%>
        <% if (m[5]!=null) { %>
           <td class="center_td bold" align="center" width="80" bgcolor="#kdfafe"><%=(String)m[5].trim()%></td>
        <%} else {%>  
           <td class="center_td bold" align="center" width="80" bgcolor="#kdfafe"></td>
        <%}%>
        <% if (m[6]!=null) { %>
           <td class="center_td bold" align="center" width="80" bgcolor="#kdfafe"><%=(String)m[6].trim()%></td>
        <%} else {%>  
           <td class="center_td bold" align="center" width="80" bgcolor="#kdfafe"></td>
        <%}%>        
        <% if (m[7]!=null) { %>
           <td class="center_td bold" align="center" width="80" bgcolor="#kdfafe"><%=(String)m[7].trim()%></td>
        <%} else {%>  
           <td class="center_td bold" align="center" width="80" bgcolor="#kdfafe"></td>
        <%}%>                                                                       
      </tr>            
	  <%} else { %>
      <tr>
        <td align="center" width="60"><input name="IsRepeatDealer" id="IsRepeatDealer" type="checkbox" value="<%=returnvalue%>"/></td>
        <% if (m[0]!=null) { %>
           <td class="center_td bold" align="center" width="80" bgcolor="#effafe"><%=(String)m[0].trim()%></td>
        <%} else {%>  
           <td  class="center_td bold" align="center" width="80" bgcolor="#effafe"></td>
        <%}%>
        <% if (m[1]!=null) { %>
           <td class="center_td bold" align="center" width="190" bgcolor="#effafe"><%=(String)m[1].trim()%></td>
        <%} else {%>  
           <td class="center_td bold" align="center" width="190" bgcolor="#effafe"></td>
        <%}%>
        
        <% if (m[2]!=null) { %>
           <td class="center_td bold" align="center" width="415" bgcolor="#effafe"><%=(String)m[2].trim()%></td>
        <%} else {%>  
           <td class="center_td bold" align="center" width="415" bgcolor="#effafe"></td>
        <%}%>        
        
        <% if (m[3]!=null) { %>
           <td class="center_td bold" align="center" width="60" bgcolor="#effafe"><%=(String)m[3].trim()%></td>
        <%} else {%>  
           <td class="center_td bold" align="center" width="60" bgcolor="#effafe"></td>
        <%}%>
        <% if (m[4]!=null) { %>
           <td class="center_td bold" align="center" width="80" bgcolor="#effafe"><%=sf.format(sf.parse((String)m[4].trim()))%></td>
        <%} else {%>  
           <td class="center_td bold" align="center" width="80" bgcolor="#effafe"></td>
        <%}%>
        <% if (m[5]!=null) { %>
           <td class="center_td bold" align="center" width="80" bgcolor="#effafe"><%=(String)m[5].trim()%></td>
        <%} else {%>  
           <td class="center_td bold" align="center" width="80" bgcolor="#effafe"></td>
        <%}%>
        <% if (m[6]!=null) { %>
           <td class="center_td bold" align="center" width="80" bgcolor="#effafe"><%=(String)m[6].trim()%></td>
        <%} else {%>  
           <td class="center_td bold" align="center" width="80" bgcolor="#effafe"></td>
        <%}%>        
        <% if (m[7]!=null) { %>
           <td class="center_td bold" align="center" width="80" bgcolor="#effafe"><%=(String)m[7].trim()%></td>
        <%} else {%>  
           <td class="center_td bold" align="center" width="80" bgcolor="#effafe"></td>
        <%}%>                                                                        
      </tr>	  
	  <%} %>
      <%}} %>           
  </tbody>
</table>
</form>
  <div style="font-size: 12px; line-height: 25px; clear:both; padding:10px 0px;"></div>
</div>
<div id="footer"></div>
</body>
</html>
